﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace patchPack
{
	class AESMod
	{
		// AES 加密(基础库)
		public static string AESEncrypt(string EncryptString, string Key, string IV)
		{
			byte[] byt = Encoding.UTF8.GetBytes(EncryptString);
			Byte[] bKey = Encoding.UTF8.GetBytes(Key);
			Byte[] bVector = Encoding.UTF8.GetBytes(IV);
			Byte[] Cryptograph = null;
			Rijndael Aes = Rijndael.Create();
			using (MemoryStream Memory = new MemoryStream())
			{
				using (CryptoStream Encryptor = new CryptoStream(Memory, Aes.CreateEncryptor(bKey, bVector), CryptoStreamMode.Write))
				{
					Encryptor.Write(byt, 0, byt.Length);
					Encryptor.FlushFinalBlock();
					Cryptograph = Memory.ToArray();
				}
			}
			return Convert.ToBase64String(Cryptograph);
		}

		// AES 加密（使用默认KEY和IV）
		public static string AESEncrypt(string EncryptString)
		{
			return AESEncrypt(EncryptString, "Aw+DcMgh=EwffZqW", "kXwL7X2+fgM=wuMd");
		}

		// AES 加密 （使用默认IV）
		public static string AESEncrypt(string EncryptString, string Key)
		{
			return AESEncrypt(EncryptString, Key, "kXwL7X2+fgM=wuMd");
		}
	}
}
